from selenium.webdriver.support.select import Select
from selenium.webdriver.common.keys import Keys
class Base():
    # 初始化方法
    def __init__(self,driver):
        self.driver=driver
    # 连接网址
    def open_url(self,url):
        self.driver.get(url)
    # 定位
    def find_element(self,loc):
        return self.driver.find_element(*loc)
    # 点击
    def click(self,loc):
        self.find_element(loc).click()
    # 输入
    def send_keys(self,loc,info):
        self.find_element(loc).send_keys(info)
    # 切换页面
    def window_to(self):
        self.driver.switch_to.window(self.driver.window_handles[-1])
    # 下滑800
    def xiahua(self,x):
        self.driver.execute_script(f"window.scrollTo(0,{x})")
    # 下拉框
    def value(self,loc,num):
        value=Select(self.find_element(loc))
        value.select_by_value(num)
    def text(self,loc,num):
        text=Select(self.find_element(loc))
        text.select_by_visible_text(num)
    # 弹窗
    def tanchaung(self):
        alert = self.driver.switch_to.alert
        alert.accept()
    def huiche(self,loc):
        self.send_keys(loc,Keys.ENTER)
    # 断言
    def duanyan(self,loc):
        self.find_element(loc).text()


